package com.xszx.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xszx.entity.MoveWarehouse;
import com.xszx.entity.dto.MoveWarehouse.MoveWarehouseQueryRequest;
import com.xszx.service.MoveWarehouseService;
import com.xszx.utils.ResultUtils;
import com.xszx.vo.AjaxJson;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/moveWarehouse")
public class MoveWarehouseController {
    @Resource
    private MoveWarehouseService moveWarehouseService;

    @RequestMapping("/moveWareList")
    public AjaxJson getMoveWareList(@RequestBody MoveWarehouseQueryRequest moveWarehouseQueryRequest){
        if (moveWarehouseQueryRequest == null){
        throw new RuntimeException("参数错误");
    }
    // 当前页
    int current = moveWarehouseQueryRequest.getCurrent();
    // 当前页的容纳条数
    int pageSize = moveWarehouseQueryRequest.getPageSize();

    // 分页查询，拦截 sql，进行分页操作
        PageHelper.startPage(current, pageSize);
    List<MoveWarehouse> moveWareInfoList = moveWarehouseService.getMoveWareList(moveWarehouseQueryRequest);

        if (moveWareInfoList == null){
        return ResultUtils.error("参数错误");
    }

    PageInfo<MoveWarehouse> MoveWarePageInfo = new PageInfo<>(moveWareInfoList);
        return ResultUtils.success(moveWareInfoList);
}

}
